class Solution {
public:
    vector<vector<int>> rangeAddQueries(int n, vector<vector<int>>& queries) {
        vector diff(n+2, vector<int>(n+2, 0)); //差分数组, 所有下标全部+1考虑
        for(auto &op:queries) {
            int row1=op[0], col1=op[1], row2=op[2], col2=op[3];
            diff[row1+1][col1+1]++;
            diff[row1+1][col2+2]--;
            diff[row2+2][col1+1]--;
            diff[row2+2][col2+2]++;
        }

        vector ans(n, vector<int>(n, 0));
        for(int i=0; i<n; i++)
            for(int j=0; j<n; j++) {
                diff[i+1][j+1]+=diff[i+1][j]+diff[i][j+1]-diff[i][j];
                ans[i][j]=diff[i+1][j+1];
            }
        return ans;
    }
};